<?php

	if(!empty($_FILES)){
		
		$tempFile = $_FILES['Filedata']['tmp_name'];
		$targetPath = "../../../".$_GET['p'];
		
		if($_GET['p'] == "admin/provisoria/"){
			
			mkdir($targetPath, 0777);
	
		}else{
			
			if(!is_dir($targetPath)){
				mkdir($targetPath, 0777);
			}
		
		}
		
		$rename = "img_";
		for($i=0; $i<4; $i++){ 
			$rename .= rand(0, 9);
		}
		
		$targetFile =  str_replace('//', '/', $targetPath) . $rename.".".strtolower(substr($_FILES['Filedata']['name'], -3));
			
		move_uploaded_file($tempFile, $targetFile);
		echo str_replace($dir, '', $targetFile);
	}

?>